package com.ruoyi.web.wuliu.service.impl;

import com.ruoyi.app.utils.AjaxResult;
import com.ruoyi.app.utils.AppUserUtils;
import com.ruoyi.common.enums.AppUserStatus;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.web.wuliu.domain.AppUser;
import com.ruoyi.web.wuliu.mapper.AppUserMapper;
import com.ruoyi.web.wuliu.service.IAppUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息Service业务层处理
 * 
 * @author 呵呵
 * @date 2023-11-16
 */
@Service
public class AppUserServiceImpl implements IAppUserService
{
    @Resource
    private AppUserMapper appUserMapper;

    /**
     * 查询用户信息
     * 
     * @param id 用户信息主键
     * @return 用户信息
     */
    @Override
    public AppUser selectAppUserById(String id)
    {
        return appUserMapper.selectAppUserById(id);
    }

    @Override
    public AppUser newSelectAppUserById(String id) {
        return appUserMapper.selectAppUserById(id);
    }

    /**
     * 查询用户信息列表
     * 
     * @param appUser 用户信息
     * @return 用户信息
     */
    @Override
    public List<AppUser> selectAppUserList(AppUser appUser)
    {
        return appUserMapper.selectAppUserList(appUser);
    }

    /**
     * 新增用户信息
     * 
     * @param appUser 用户信息
     * @return 结果
     */
    @Override
    public int insertAppUser(AppUser appUser)
    {
        appUser.setCreateTime(DateUtils.getNowDate());
        return appUserMapper.insertAppUser(appUser);
    }

    /**
     * 修改用户信息
     * 
     * @param appUser 用户信息
     * @return 结果
     */
    @Override
    public int updateAppUser(AppUser appUser)
    {
        appUser.setUpdateTime(DateUtils.getNowDate());
        return appUserMapper.updateAppUser(appUser);
    }

    /**
     * 批量删除用户信息
     * 
     * @param ids 需要删除的用户信息主键
     * @return 结果
     */
    @Override
    public int deleteAppUserByIds(String[] ids)
    {
        return appUserMapper.deleteAppUserByIds(ids);
    }

    /**
     * 删除用户信息信息
     * 
     * @param id 用户信息主键
     * @return 结果
     */
    @Override
    public int deleteAppUserById(String id,String status)
    {
        AppUser appUser = appUserMapper.selectAppUserById(id);
        Assert.notNull(appUser,"用户不存在");
        appUser.setStatus(status);
        return appUserMapper.updateAppUser(appUser);
    }

    @Override
    public AjaxResult<String> signIn(AppUser user) {
        AppUser appUserTemp = AppUserUtils.getAppUser();
        AppUser appUser = appUserMapper.selectAppUserById(appUserTemp.getId());
        Assert.notNull(appUser,"用户不存在");
        user.setStatus(AppUserStatus.UNDERREVIEW.getCode());
        appUserMapper.updateAppUser(user);
        return new AjaxResult<String>("0","添加成功");
    }
}
